package com.hp.controller;

import com.hp.annotation.Power;
import com.hp.entity.ResourcesType;
import com.hp.result.DataGridResultInfo;
import com.hp.result.SubmitResultInfo;
import com.hp.service.ResourcesTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Power(name = "资源类型管理",type =0)
@Controller
@RequestMapping("/resources")
public class ResourcesTypeController {

    @Autowired
    private ResourcesTypeService resourcesTypeService;

    /**
     * 去资源分类页面list
     *
     * @return
     */
    @Power(name = "去资源分类页面list",type =1,url = "/resources/querytyperesources")
    @GetMapping("/querytyperesources")
    public String querytyperesources() {

        return "/resourcestype/querytyperesources";
    }

    /**
     * 分页接口
     *
     * @param page
     * @param rows
     * @param resourcesType
     * @return
     */
    @Power(name = "资源分类列表",type =1,url = "/resources/querytyperesources_result")
    @ResponseBody
    @RequestMapping("/querytyperesources_result")
    public DataGridResultInfo querytyperesources_result(@RequestParam(name = "page", defaultValue = "1") int page,
                                                        @RequestParam(name = "rows", defaultValue = "10") int rows, ResourcesType resourcesType) throws Exception {


        return resourcesTypeService.pageresourcetype(page, rows, resourcesType);

    }

    /**
     * 去添加页面
     * @return
     */
    @Power(name = "去添加页面",type =1,url = "/resources/addtype")
    @GetMapping("/addtype")
    public String toadd() {

        return "/resourcestype/addreousercestype";
    }

    /**
     * 添加类型
     * @param resourcesType
     * @return
     * @throws Exception
     */
    @Power(name = "添加类型",type =1,url = "/resources/addsubmit")
    @ResponseBody
    @PostMapping("addsubmit")
    public SubmitResultInfo addsubmit(ResourcesType resourcesType)throws Exception{

        return resourcesTypeService.savetype(resourcesType);
    }

    /**
     * 去类型修改界面
     * @param id
     * @param map
     * @return
     */
    @Power(name = "去类型修改界面",type =1,url = "/resources/toupdatetype")
    @GetMapping("/toupdatetype")
    public String toupdate(String id,Map<String,Object> map) throws Exception {
        map.put("psr",resourcesTypeService.findTypeById(id));
        return "/resourcestype/updateresourcestype";
    }


    /**
     * 修改类型
     * @param resourcesType
     * @return
     */
    @Power(name = "修改类型",type =1,url = "/resources/upadtesubmit")
    @ResponseBody
    @PostMapping("/upadtesubmit")
    public SubmitResultInfo upadtesubmit(ResourcesType resourcesType) throws Exception {

        return resourcesTypeService.updatetype(resourcesType);
    }

    /**
     * 删除
     * @param typeid
     * @return
     */
    @Power(name = "删除",type =1,url = "/resources/deletetype")
    @ResponseBody
    @PostMapping("/deletetype")
    public SubmitResultInfo deletetype(String typeid) throws Exception {

        return resourcesTypeService.deletetype(typeid);
    }
}
